attribute vec3 toPosition;
uniform float progress;
varying vec3 color;
varying vec2 vUv;
uniform sampler2D map;
uniform sampler2D toMap;

void main() {
    vec3 pos = position;
    vec3 from = texture2D(map, uv).rgb;
    vec3 to = texture2D(toMap, uv).rgb;
    vUv = uv;

    vec3 disC = to - from;

    color = from + disC * progress;

    vec3 dis = toPosition - position;
    if(progress < 1.) {
        pos = position + progress * dis;
    } else {
        pos = toPosition;
    }

    vec4 viewPosition = modelViewMatrix * vec4(pos, 1.0);
    gl_Position = projectionMatrix * viewPosition;
    gl_PointSize = 0.2;
    gl_PointSize *= 200. / -(modelViewMatrix * vec4(pos, 1.0)).z;
}